import type {ProColumns} from '@ant-design/pro-components';
import {ProTable} from '@ant-design/pro-components';
import { Modal } from 'antd';
import React, {useEffect, useRef} from 'react';
import {val} from "@umijs/utils/compiled/cheerio/lib/api/attributes";
import {values} from "lodash";
import {ProFormInstance} from "@ant-design/pro-form/lib";

//import InterfaceInfo = API.InterfaceInfo;


export type Props = {
  values:API.InterfaceInfo;
  columns: ProColumns<API.InterfaceInfo>[];
  onCancel: () => void;
  onSubmit: (values:API.InterfaceInfo) => Promise<void>;
  visible: boolean;

};

const UpdateModal: React.FC<Props> = (props) => {
  // const intl = useIntl();
  const {values,visible,columns,onCancel,onSubmit}=props;
  const formRef =useRef<ProFormInstance>();
  useEffect(()=>{
    if (formRef){
      formRef.current?.setFieldsValue(values);
    }

  },[values])
  return (
    <Modal visible={visible} footer={null} onCancel={()=>onCancel?.()} >
      <ProTable type={"form"} columns={columns}
                formRef={formRef}
                onSubmit={async (value) => {
        onSubmit?.(value);

      }}
      />;
    </Modal>


  )}

export default UpdateModal;
